package cn.seqdata.forecast.model.smoothing;

import cn.seqdata.forecast.model.AbstractModel;
import cn.seqdata.forecast.model.ModelParams;
import org.hawkular.datamining.forecast.AutomaticForecaster;
import org.hawkular.datamining.forecast.models.Model;
import org.hawkular.datamining.forecast.models.TripleExponentialSmoothing;
import org.hawkular.datamining.forecast.utils.JodaUtils;
import org.joda.time.ReadableInterval;
import org.joda.time.ReadablePeriod;

/**
 * @author jrxian
 */
public class TripleExponentialSmoothingModel extends ExponentialSmoothingModel {

    @Override
    public AbstractModel<ModelParams> create(ModelParams params) {
        TripleExponentialSmoothingModel model = new TripleExponentialSmoothingModel();

        model.create(Model.TripleExponentialSmoothing, params);

        ReadableInterval interval = getParams().getInterval();
        ReadablePeriod period = getParams().getPeriod();
        int size = JodaUtils.size(interval, period);

        TripleExponentialSmoothing usedModel = TripleExponentialSmoothing.createWithSmoothingParams(size,    //
                params.getDouble("levelSmoothing"), params.getDouble("trendSmoothing"),    //
                params.getDouble("seasonalSmoothing"));
        model.setForecaster(new AutomaticForecaster(context, config, usedModel));

        return model;
    }
}
